package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.jaxb.SpringDataJaxb;
import org.springframework.web.bind.annotation.*;

@RestController("adminOderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端-订单接口")
public class OrderController {
    @Autowired
    OrderService orderService;

    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO){
        return Result.success (orderService.adminPage(ordersPageQueryDTO));
    }
    @GetMapping("/details/{id}")
    @ApiOperation("单个订单")
    public Result<OrderVO> detail(@PathVariable Long id){
        return Result.success (orderService.adminDetail(id));
    }
    @GetMapping("/statistics")
    @ApiOperation("订单状态统计")
    public Result<OrderStatisticsVO> statistics(){
        return Result.success (orderService.statistics());
    }
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result agree(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.agree(ordersConfirmDTO);
        return Result.success ();
    }
    @PutMapping("/rejection")
    @ApiOperation("拒绝单")
    public Result reject(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        orderService.reject(ordersRejectionDTO);
        log.info("拒单");
        return Result.success ();
    }
    @PutMapping("/cancel")
    @ApiOperation("取消单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderService.adminCancel(ordersCancelDTO);
        return Result.success ();
    }
    @PutMapping("/delivery/{id}")
    @ApiOperation("发送快递单")
    public Result delivery(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success ();
    }
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable("id") Long id) {
        orderService.complete(id);
        return Result.success();
    }
}
